
#include "../ui.h"
#include "../gui.h"
#include "../app_includes.h"

//lv_obj_t *mbox;  

static void msg_close_timer_cb(lv_timer_t *timer)
{
    lv_obj_t *mbox = timer->user_data;
    
    lv_msgbox_close_async(mbox);
    lv_timer_del(timer);
}

void msg_show_auto_close(char *title, char *txt, uint32_t delay)
{  
    lv_obj_t *label;
    lv_obj_t *mbox = lv_msgbox_create(ui_main_screen.desktop,title,txt,NULL,NULL);
    lv_obj_set_size(mbox, lv_pct(80), lv_pct(40));
    lv_obj_align(mbox, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_style_bg_color(mbox, lv_color_hex(0xCFCFCF), LV_PART_MAIN | LV_STATE_DEFAULT );

    lv_timer_create(msg_close_timer_cb, delay, mbox);
    label = lv_msgbox_get_title(mbox);
    lv_obj_set_style_text_color(label, lv_color_hex(0xC86464), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_text_font(label, &lv_font_montserrat_22, LV_PART_MAIN| LV_STATE_DEFAULT);
    label = lv_msgbox_get_text(mbox);
    lv_obj_set_style_text_color(label, lv_color_hex(0xC86464), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_text_font(label, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);
}
